ARG APISIX_VERSION=3-debian-12
ARG APISIX_ETCD_VERSION=3.5-debian-12
ARG APISIX_DASHBOARD_VERSION=3-debian-12
FROM bitnami/etcd:${APISIX_ETCD_VERSION} AS etcd-stage

FROM bitnami/apisix-dashboard:${APISIX_DASHBOARD_VERSION} AS dashboard

FROM bitnami/apisix:${APISIX_VERSION}

COPY --from=etcd-stage /opt/bitnami/etcd /opt/bitnami/etcd
COPY --from=etcd-stage /opt/bitnami/scripts /opt/bitnami/scripts
COPY --from=dashboard /opt/bitnami/apisix-dashboard /opt/bitnami/apisix-dashboard

USER root

RUN mkdir -p /bitnami/etcd && chmod g+rwX /bitnami/etcd
VOLUME /bitnami/etcd

RUN mkdir -p /opt/bitnami/apisix-dashboard/logs && chmod g+rwX /opt/bitnami/apisix-dashboard/logs
VOLUME /opt/bitnami/apisix-dashboard/logs

RUN mkdir -p /opt/bitnami/apisix/logs && chmod g+rwX /opt/bitnami/apisix/logs
VOLUME /opt/bitnami/apisix/logs

COPY ./docker-entrypoint.sh /docker-entrypoint.sh

RUN chmod +x /docker-entrypoint.sh

ENV PATH="/opt/bitnami/common/bin:/opt/bitnami/etcd/bin:/opt/bitnami/apisix-dashboard:$PATH"

WORKDIR /opt/bitnami/apisix-dashboard

EXPOSE 9080 9443 9000

USER apisix

ENTRYPOINT ["sh", "-c", "(/opt/bitnami/scripts/etcd/entrypoint.sh /opt/bitnami/scripts/etcd/run.sh &) && sleep 10 && (/opt/bitnami/apisix-dashboard/manager-api &) && sleep 5 &&  (/docker-entrypoint.sh docker-start)"]

STOPSIGNAL SIGQUIT

